package com.saascloud.redis.core;

import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @author:one_dream@aliyun.com
 * @createDate:2022/8/21 23:51
 * @description:
 */
public class SaasStringRedisTemplate extends RedisTemplate<String, String> {


    public SaasStringRedisTemplate() {
        SaasRedisKeySerializer saasRedisKeySerializer = new SaasRedisKeySerializer();
        setKeySerializer(saasRedisKeySerializer);
        setValueSerializer(RedisSerializer.string());
        setHashKeySerializer(RedisSerializer.string());
        setHashValueSerializer(RedisSerializer.string());
    }


    public SaasStringRedisTemplate(RedisConnectionFactory connectionFactory) {
        this();
        setConnectionFactory(connectionFactory);
        afterPropertiesSet();
    }

    protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) {
        return new DefaultStringRedisConnection(connection);
    }
}
